# -*- coding: utf-8 -*- 

#from google.appengine.api import users
from google.appengine.ext import webapp
from model import ShareCategory,ShareLink,ShareCategoryLink,_today
from base import *

class GetCategories(BaseRequestHandler):
    def get(self):
         # categories
        categories = ShareCategory.all()
        categories.order('-name')

        values = []
        for category in categories:
            c = {}
            c['name'] = category.name
            c['title'] = category.title
            values.append(c)

        import simplejson as simplejson
        html = simplejson.dumps(values)

        self.response.out.write(html)
        
class ConvertToSAE(BaseRequestHandler):
    def get(self):
         # categories
        categories = ShareCategory.all()
        categories.order('-name')

        shares = ShareLink.all()
        
        #sql_link = "INSERT INTO `share_link` (`link_id`, `link_create_time`, `link_short_code`, `link_origin_url`, `link_content`, `link_title`, `link_user_id`,`link_visit_count`) Values"

        values={
            'shares':shares,
            'categories':categories,
        }
        
        html = self.get_render("views/convert.html",values)
        self.write(html)